package com.zh.chat.controller;

import com.zh.chat.dao.FriendsDAO;
import com.zh.chat.dao.UserDAO;
import com.zh.chat.dao.impl.FriendsDAOImpl;
import com.zh.chat.dao.impl.UserDAOImpl;
import com.zh.chat.net.TCPNetDTO;
import com.zh.chat.net.UDPNetDTOImpl;
import com.zh.chat.service.impl.NetServiceImpl;

public class Main {
	public static void main(String[] args) {
		com.zh.chat.file.ConfigUtil config = new com.zh.chat.file.ConfigUtil();
		//初始化数据库访问类
		UDPNetDTOImpl udpDTO = new UDPNetDTOImpl(config);
		TCPNetDTO tcpDTO = new TCPNetDTO(config);
		tcpDTO.setUDPNetDTO(udpDTO);
		NetServiceImpl netService = new NetServiceImpl();
		netService.setUDPNetDTO(udpDTO);
		netService.setTCPNetDTO(tcpDTO);
		
		UserDAO userService= new UserDAOImpl();
		FriendsDAO friendsService = new FriendsDAOImpl();
		
		//初始化文本传输模块
		//NetDTO cmdDTO = (NetDTO)Factory.getInstance("CommandDTO");
		//cmdDTO.setConfig(config);
		//初始化图片传输模块
		//ImageDTO imgDTO=(ImageDTO)Factory.getInstance("ImageDTO");
		//imgDTO.setConfig(config);
		//初始化数据存储模块
		//ChatDAO chatDAO = (ChatDAO)Factory.getInstance("ChatDAO");
		//初始化核心控制类
		ServerController serverController = ServerController.getInstance();
		serverController.setNetService(netService);
		serverController.setUserService(userService);
		serverController.setFriendsService(friendsService);
		serverController.start();
		/**
		 * 设置请求处理模块
		 */
		//chatDAO.setNetService(cmdDTO);				//ChatDAO->netDTO
		//chatDAO.setDBContext(dbContext); 	//ChatDAO->entityContext
		//chatDAO.setConfigUtil(config);
		/**
		 * 设置回复信息的通讯模块
		 */
		//ChatRspDTO.setConfigUtil(config);
		//ChatRspDTO.setCmdDTO(cmdDTO);
		//ChatRspDTO.setImgDTO(imgDTO);
		//ChatRspDTO.setDataDAO(chatDAO);
		/**
		 * 设置核心控制类
		 */
		//serverController.setDataService(chatDAO); 		//serverContext->ChatDAO
		//serverController.setNetDTOImpl(cmdDTO); 		//serverContext->netDTO
		//serverController.setChatResponse(ChatRspDTO);	//serverContext->ChatRspDTO
		
		//dbContext.conn();//启动数据库连接
		//serverController.start();//启动服务器
		//关闭所有对象中的socket和数据流
		//cmdDTO.close();
		//imgDTO.close();
		//关闭数据库连接
		//dbContext.closeConn();
	}
}
